package com.zhiyin.seal.config;

import com.zhiyin.seal.payment.IWXPayDomain;
import com.zhiyin.seal.payment.WXPayConfig;
import org.springframework.util.ClassUtils;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import static com.zhiyin.seal.payment.WXPayConstants.*;

public class MyWXPayConfig extends WXPayConfig {
    private byte[] certData;

    public MyWXPayConfig() throws Exception {
        String certPath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + WX_CER;
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public String getAppID() {
        return APP_ID;
    }

    public String getMchID() {
        return MCH_ID;
    }

    public String getKey() {
        return KEY;
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        return new MyWXPayDomain();
    }

}
